ABC256 C - Filling 3x3 array
提出
code: python
h1, h2, h3, w1, w2, w3 = list(map(int, input().split()))
# 分け方がそれぞれあって、それを全探索していく?
解答
code: python
h1, h2, h3, w1, w2, w3 = list(map(int, input().split()))
ans = 0
for a in range(1, 31):
for b in range(1, 31):
for d in range(1, 31):
for e in range(1, 31):
c = h1 - a - b
f = h2 - d - e
g = w1 - a - d
h = w2 - b - e
i = w3 - c - f
if (min(c, f, g, h, i) > 0 and g + h + i == h3):
ans += 1
print(ans)
メモ
提出
code: python
h1, h2, h3, w1, w2, w3 = list(map(int, input().split()))
# print(pow(28, 9)) 10^13
# a b c
# d e f
# g y z
ans = 0
for i in range(1, 29):
a = i
for j in range(1, 29):
b = j
for k in range(1, 29):
d = k
for l in range(1, 29):
e = l
c = h1 - (a + b)
if c < 1:
continue
f = h2 - (d + e)
if f < 1:
continue
g = w1 - (a + d)
if g < 1:
continue
y = w2 - (b + e)
if y < 1:
continue
if w3 - (c + f) < 1 or h3 - (g + y) < 1 or w3 - (c + f) != h3 - (g + y):
continue
ans += 1
print(ans)